package com.itheima.sky.controller.front;

import com.itheima.sky.entity.Result;
import com.itheima.sky.pojo.Orders;
import com.itheima.sky.service.OrderService;
import com.itheima.sky.vo.OrderVO;
import com.itheima.sky.vo.PageResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * @Description OrderController
 * @Author jiangning
 * @Date 2024-06-28
 */
@RestController
@Slf4j
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;

    @PostMapping("/submit")
    public Result submitOrder(@RequestBody Orders order, HttpSession session){
        Long userId =(Long) session.getAttribute("userId");
        orderService.submitOrder(order,userId);
        return Result.success("提交成功");
    }
    @GetMapping("/userPage")
    public Result getOrdersInUserPage(HttpSession session,Integer page,Integer pageSize){
        Long userId =(Long) session.getAttribute("userId");
        PageResultVO<OrderVO> ordersInUserPage = orderService.getOrdersInUserPage(userId, page, pageSize);
        return Result.success(ordersInUserPage);
    }
}
